package com.uplooking.spider.utils;

import ch.qos.logback.core.net.SyslogOutputStream;
import com.uplooking.spider.constant.PageConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class PageUtil {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    /**
     * 获取当前页码并且页码跳到下一页
     *
     * @return 当前页码
     */
    public String getCurrentPageNumAndSkipNextPage() {
        String pageNum = redisTemplate.boundValueOps(PageConstant.CURRENT_PAGE_NUM).get();
        if (pageNum == null) {
            redisTemplate.boundValueOps(PageConstant.CURRENT_PAGE_NUM).set("0");
            pageNum = redisTemplate.boundValueOps(PageConstant.CURRENT_PAGE_NUM).get();
        }
        redisTemplate.boundValueOps(PageConstant.CURRENT_PAGE_NUM).set(String.valueOf(Integer.valueOf(pageNum) + 50));
        return pageNum;
    }
}
